<template>
	<!-- 
	swiper中的transfrom会使fixed失效,此时用height="100%"固定高度; 
	swiper中无法触发mescroll-mixins.js的onPageScroll和onReachBottom方法,只能用mescroll-uni,不能用mescroll-body
	-->
	<!-- ref动态生成: 字节跳动小程序编辑器不支持一个页面存在相同的ref (如不考虑字节跳动小程序可固定值为 ref="mescrollRef") -->
	<mescroll-uni ref="mescrollRef" height="100%" @init="mescrollInit" bottom="80" :down="downOption"
		@down="downCallback" :up="upOption" @up="upCallback">
		<!-- 数据列表 -->
		<view class="item" v-for="(item,indexs) in list" :key="indexs">
			<listItem :source="item" :index="index" @refresh="downCallback"></listItem>
		</view>
		<!-- <uni-load-more v-if="list.length>1" :status="status" color="#1EAF22" :icon-size="16" style="margin-bottom: 20upx;" :content-text="contentText" /> -->
		<!-- <view class="nodata-wrapper" v-if="!list.length">
			<view class="loading-wrapper loading-image" style="position: relative;display: inline-block;" v-if="isLoading">
				<zero-loading  type="love"  position="absolute"></zero-loading>
			</view>
			<image v-else src="../../../../static/image/noorder.png" class="nodata-image" mode="widthFix"></image>
			<view class="text">
				 {{isLoading?'数据加载中...':'暂无订单'}}
			</view>
		</view> -->
	</mescroll-uni>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";
	import listItem from '@/subPage_transport/listItem.vue'

	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				downOption: {
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: false, // 不自动加载
					textNoMore: '没有更多啦~',
					noMoreSize: 3, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						fixed: true,
						top: '200upx',
						tip: '~ 空空如也 ~', // 提示
						icon: 'https://sm.hobon.cc/static/hobon_noorder.png'
					}
				},
				isLoading: true,
				//mescroll:'',
				list: [],
				pageNum: 1,
				pageSize: 10,
				//org: this.$store.state.userInfo.orgRelation.org,
			}
		},
		props: {
			i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
				type: Number,
				default () {
					return 0
				}
			},
			keywords: {
				type: String,
				default () {
					return ''
				}
			},
			dispatchDate: {
				type: String,
				default () {
					return ''
				}
			}
		},
		methods: {
			refresh() {
				this.mescroll.scrollTo(0, 0)
				this.$nextTick(() => {
					this.mescroll.resetUpScroll()
				})
			},
			refreshData(data) { //局部刷新数据

			},
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			getData() {
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			async upCallback(page) {
				let status = []
				// if (this.index === 0) {
				// 	status = [1];
				// } else if (this.index === 1) {
				// 	status = [2, 3, 4];
				// }
				this.pageNum = page.num;
				const params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					orders: [{
						"asc": false,
						"column": "id"
					}],
					meetCarType: this.index === 0 ? 'MEET_CAR' : 'ARRIVED_CAR',
					//dispatchDate: this.dispatchDate,
					//dispatchDate: '2024-10-21',
					pickupPointId: this.$store.state.userInfo.pickupPointId
				};
				let url = '';

				const data = await this.$api.post('/app/transport/transportList', params, false)
				if (data.code === 200) {
					this.isLoading = false;
					if (this.pageNum === 1) {
						this.list = [];
					}
					data.data.forEach(item => {
						item.arrivalDate = '-';
						if (item.transportTracking) {
							const transportTracking = JSON.parse(item.transportTracking)
							const obj = transportTracking.find(row => row.pickupPointId === this.$store.state
								.userInfo.pickupPointId)
							item.arrivalDate = obj ? obj.dateTime.substring(0, 10) : '-';
						}
					})
					this.list = this.list.concat(data.data);
					this.mescroll.endBySize(data.data.length, data.data.length);
				} else {
					this.mescroll.endErr();
				}
			},
			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			}
		},
		components: {
			listItem
		}
	}
</script>
<style lang="scss" scope>
	.item {
		margin: 0 20upx;
		border-radius: 20upx;
		background-color: #ffffff;
		margin-bottom: 20upx;
	}

	.nodata-wrapper {
		text-align: center;
		font-size: 32upx;
		color: #666666;

		.nodata-image {
			margin-top: 300upx;
			margin-bottom: 10upx;
			width: 246upx;
		}

		.loading-image {
			margin-top: 300upx;
			margin-bottom: 10upx;
			width: 296upx;
			height: 205upx;
		}
	}
</style>